package com.mp.approvalreq.servlet;

import com.alibaba.fastjson.JSONObject;
import com.mp.approvalreq.service.SelectApprovalServicePrx;
import com.plusmoney.util.ParameterUtils;
import com.qq.tars.client.util.ServantUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getRequestStatus")
public class GetRequestStatus extends AbstractServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		try {
			Integer id = ParameterUtils.getIntegerParameter(req, "id");

			SelectApprovalServicePrx selectApprovalServicePrx = ServantUtils.getObject(SelectApprovalServicePrx.class);

			Integer finished = selectApprovalServicePrx.getRequestStatusById(id);

			returnResp(resp, finished);
		} catch (Throwable e) {
			onThrowable(req, resp, e);
		}
	}

	private void returnResp(HttpServletResponse resp, Integer finished) throws IOException {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("result", "0");
		jsonObject.put("res_info", "获得成功");
		jsonObject.put("finished", finished);

		printJson(resp, jsonObject.toJSONString());
	}
}
